﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using MongoDB.Driver;

namespace K2.Sync.Service
{
    public class MongoFactory
    {
        private static IMongoDatabase db;
        private static object _lock = new object();
        private MongoFactory() { }

        public static IMongoDatabase GetDatabase()
        {
            if (db == null)
            {
                lock (_lock)
                {
                    if (db == null)
                    {
                        var url = new MongoUrl("mongodb://127.0.0.1:27017/k2");
                        var client = new MongoClient(url);
                        db = client.GetDatabase(url.DatabaseName);
                    }
                }
            }
            return db;
        }
    }
}
